package org.bluedream.core.module.controller.fixed;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.bluedream.comm.base.BaseController;
import org.bluedream.comm.utils.RestResult;
import org.bluedream.core.config.advice.RsaSecurityParameter;
import org.bluedream.core.module.entity.fixed.Fixed;
import org.bluedream.core.module.entity.goods.Goods;
import org.bluedream.core.module.service.fixed.FixedService;
import org.bluedream.core.utils.configUtil.GoalConfigUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;


/**
 * @ClassName FixedController
 * @Description TODO
 * @Author Administrator
 * @Data 2021/11/30 8:44
 * @Version
 */
@Slf4j
@Controller
@RequestMapping(value = "${adminPath}/fixed")
public class FixedController extends BaseController {
    @Resource
    private FixedService fixedService;

    @ModelAttribute
    public Fixed get(String id){
        return fixedService.getById(id);
    }

    @RequiresPermissions("fixed:view")
    @RequestMapping(value = {"/list" , ""})
    public String list(Fixed entity, Model model){
        model.addAttribute("pageSize" , GoalConfigUtil.getValueByKey("sys.page.size"));
        model.addAttribute("fixed" , entity);
        return "module/fixed/fixedList";
    }

    @RequiresPermissions("fixed:view")
    @RequestMapping("/form")
    public String form(Fixed entity, Model model){
        model.addAttribute("fixed" , entity);
        return "module/fixed/fixedForm";
    }

    @RequiresPermissions("fixed:view")
    @RequestMapping("/findPage")
    @ResponseBody
    public IPage<Fixed> findPage(@RsaSecurityParameter Fixed entity){
        return fixedService.findPage(entity);
    }

    @RequiresPermissions(value = {"fixed:edit"})
    @RequestMapping("/save")
    @ResponseBody
    public RestResult save(Fixed entity){
        return fixedService.saveEntity(entity);
    }

/*    @RequiresPermissions("fixed:view")
    @RequestMapping("/depTreeData")
    @ResponseBody
    public List<Map<String , Object>> depTreeData(@RequestParam(defaultValue="1")String isShowCode){
        return depItemUserViewService.treeData(isShowCode);
    }*/

    @RequiresPermissions("fixed:view")
    @RequestMapping(value = "/goodsForm")
    public String depItemUserForm(Model model){
        model.addAttribute("pageSize" , GoalConfigUtil.getValueByKey("sys.page.size"));
        model.addAttribute("goods" , new Goods());
        return "module/goods/goodsSelect";
    }
}